package org.lyl.taobao.controller.Listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * @Author: Re
 * @Date: 2021/4/16 20:33
 */
@WebListener
public class OnlineListener implements HttpSessionListener {
    private int onlineNumber = 0;
    @Override
    public void sessionCreated(HttpSessionEvent se) {
        onlineNumber++;
        se.getSession().getServletContext().setAttribute("onlineNumber",onlineNumber);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        onlineNumber--;
        se.getSession().getServletContext().setAttribute("onlineNumber",onlineNumber);
    }
}
